// pages/member/member.js
const api = require('../../utils/interface.js')
const app = getApp()
Page({
  data: {
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
    oilType: 0,
    priceType: 0,
    state: 0,
    userInfo: null,
    isShow: true,
    stationId: ""
  },
  onShow: function() {
    getApp().login().then(res => {
      if (this.data.isShow) {
        this.getMemberInfo()
      } else {
        this.getMemberInfo()
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: "#ffffff"
        })
      }
    })
  },
  checkNum(e) {
    if (e.detail) {
      console.log(e.detail)
      this.setData({
        state: 1,
      })
    }
  },
  // 获取会员信息
  getMemberInfo() {
    let user = wx.getStorageSync('userInfo')
    if (user) {
      api.getMemberInfo({id:user.id}).then(res=>{
        console.log(res.data.result)
        if (res.data.result.firstMemberInfoCardDTO){
          wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: "#ffffff"
          })
          this.setData({
            state: 1,
            userInfo: res.data.result
          })
        }else{
          wx.setNavigationBarColor({
            frontColor: '#000000',
            backgroundColor: "#000000"
          })
          this.setData({
            state: 2,
            userInfo: res.data.result
          })
        }
      })
      
    } else {
      wx.setNavigationBarColor({
        frontColor: '#000000',
        backgroundColor: "#000000"
      })
      this.setData({
        state: 2,
        userInfo: null
      })
    }
  },
  onHide() {
    this.data.isShow = true
  }
})